home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Applications / Alpha 4.01 / ACMDS / UnComment Box.c < prev    next >
C/C++ Source or Header  |  1990-12-01  |  3KB  |  124 lines

  1. /****************************************************************
  2. *                                                               *
  3. * When debugging, set the project type to application,          *
  4. * and add the ANSI project.                                     *
  5. *                                                               *
  6. * When all your bugs are out, 'undef' DEBUG, set the project    *
  7. * type to Code Resource, with type = ACMD, name = <the name     *
  8. * of the function>, file type to 'AEXT', and the purgeable      *
  9. * flag set to true.                                             *
  10. *                                                               *
  11. * Also, you need to remove the ANSI project from the ACMD       *
  12. * project and replace it with the ANSI-A4 project if you use    *
  13. * any functions in ANSI, such as strlen.                        *
  14. *                                                               *
  15. * If you are not using THINK C, I'm not quite sure what you     *
  16. * should do. :-)                                                *
  17. *                                                               *
  18. ****************************************************************/
  19.  
  20. #undef    DEBUG
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #define    STAR    '*'
  27. #define    CR        '\r'
  28.  
  29.  
  30. /**************************************************************
  31. *                                                             *
  32. * This has to be called w/ exactly the right selection,       *
  33. * namely the text from the beginning of the first comment     *
  34. * line to the beginning of the line after the last comment    *
  35. * line.                                                       *
  36. *                                                             *
  37. **************************************************************/
  38. char *
  39. #ifdef    DEBUG
  40. dummy(inStr)
  41. #else    DEBUG
  42. main(inStr)
  43. #endif    DEBUG
  44. char    *inStr;
  45. {
  46.     char    *ptr = inStr, *tptr;
  47.     size_t    sz;
  48.     
  49.     sz = GetPtrSize(inStr);
  50.     
  51.     while (*ptr)
  52.     {
  53.         if (*ptr == '/')
  54.         {
  55.             tptr = ptr;
  56.             while (*tptr++ != CR);    /* step past the star line */
  57.             while (*tptr++ != CR);    /* step past the blank line */
  58.             memmove(ptr, tptr, sz - (tptr - inStr));
  59.         }
  60.         else
  61.         {
  62.             /* must be either interior line or last line */
  63.             if (*(ptr + 1) == ' ')
  64.             {
  65.                 /* interior line */
  66.                 memmove(ptr, ptr + 2, sz - ((ptr + 2) - inStr));
  67.                 while (*ptr++ != CR);
  68.                 ptr -= 3;
  69.                 memmove(ptr, ptr + 2, sz - ((ptr + 2) - inStr));
  70.                 ptr++;
  71.             }
  72.             else
  73.             {
  74.                 /* last line, so go back and remove the blank line */
  75.                 ptr--;
  76.                 while (*--ptr != CR);
  77.                 ptr++;
  78.                 *ptr = 0;
  79.             }
  80.         }
  81.     }
  82.     return(inStr);
  83. }
  84.  
  85.  
  86. #ifdef    DEBUG
  87.  
  88. char * ConvertRtoN(char *theStr);
  89.  
  90. char * ConvertRtoN(theStr)
  91.     char *theStr;
  92. {
  93.     char *currentChar;
  94.     
  95.     for (currentChar = theStr;*currentChar != 0; currentChar++)
  96.         if (*currentChar == '\r')
  97.             *currentChar = '\n';
  98. }
  99.     
  100. main()
  101. {
  102.     char    *str = "/*********\r* this   *\r* is and *\r*********/\r";
  103.     char    *ret, *in;
  104.     
  105.     in = NewPtr(strlen(str) + 1);
  106.     strcpy(in, str);
  107.     
  108.     ret = dummy(in);
  109.     
  110.     ConvertRtoN(ret);                /* Convert '\r' to '\n' so we can see them in a printf */
  111.     ConvertRtoN(str);
  112.         
  113.     printf("The original is:\n\n%s", str);
  114.     printf("\n----\n\nThe result is:\n\n%s", ret);
  115.     
  116. }
  117. #endif    DEBUG
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.